package tk.deep.bh2;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import tk.deep.bh2.service.impl.OrderDetailService;

import javax.annotation.Resource;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

@SpringBootApplication
public class BootH2Application {

    @Resource
    OrderDetailService orderDetailService;

    public static void main(String[] args) {
        SpringApplication.run(BootH2Application.class, args);
        System.out.println(">>>");
    }

//    @Component
//    public class MyStartupRunner implements CommandLineRunner {
//
//        @Override
//        public void run(String... args) throws Exception {
//            System.out.println(">>>>>>>>>>>>>>>服务启动执行，执行加载数据等操作<<<<<<<<<<<<<");
//            orderDetailService.addNew();
//        }
//    }


    class NamedThreadFactory implements ThreadFactory {
        private final ThreadGroup group;
        private final AtomicInteger threadNumber = new AtomicInteger(1);


        NamedThreadFactory() {
            SecurityManager s = System.getSecurityManager();
            group = (s != null) ? s.getThreadGroup() :
                    Thread.currentThread().getThreadGroup();
        }

        public Thread newThread(Runnable r) {
            Thread t = new Thread(group, r,
                    threadNumber.getAndIncrement()+"",
                    0);
            if (t.isDaemon())
                t.setDaemon(false);
            if (t.getPriority() != Thread.NORM_PRIORITY)
                t.setPriority(Thread.NORM_PRIORITY);
            return t;
        }
    }
}
